#include "Subsystems/BlockBehaviors/SubsystemGravestoneBlockBehavior.h"
#include "GameSingleton.h"
#include "Subsystems/SubsystemTerrain.h"
#include "Managers/BlocksManager.h"
#include "Blocks/GravestoneBlock.h"

namespace PocketSurvival
{
    SubsystemGravestoneBlockBehavior::SubsystemGravestoneBlockBehavior()
    {
        m_handleBlocks.push_back(GravestoneBlock::Index());
    }

    void SubsystemGravestoneBlockBehavior::onNeighborBlockChanged(int32_t x, int32_t y, int32_t z, int32_t neighborX, int32_t neighborY, int32_t neighborZ)
    {
        int32_t cellContentes = m_terrain->getCellContents(x, y - 1, z);
        if(GameSingleton::blocksManager->blocks[cellContentes]->IsTransparent)
        {
            m_terrain->destroyCell(0, x, y, z, 0, false);
        }
    }

    void SubsystemGravestoneBlockBehavior::load(const nlohmann::json &json)
    {
        m_terrain = GameSingleton::singletonPtr->getSingleton<SubsystemTerrain>();
    }

    static const std::string subsystemName = "GravestoneBlockBehavior";
    const std::string &SubsystemGravestoneBlockBehavior::getName() const
    {
        return subsystemName;
    }
}
